#=============基础配置==========#
#指定cmake最低版本
cmake_minimum_required(VERSION 3.11)
#定义项目名称
PROJECT(TEST)
#指定c++17标准
set(CMAKE_CXX_STANDARD 17)
# 添加这一行，确保是Debug模式
#显式设置构建类型为Debug（调试阶段推荐，发布时可改为Release）
set(CMAKE_BUILD_TYPE Debug)

#==========依赖opencv===========#

# 查找OpenCV库
find_package(OpenCV REQUIRED
    core
    imgproc
    cudaimgproc
    cudaarithm
    cudawarping
    dnn
    highgui
    calib3d    # 添加calib3d模块（解决solvePnP错误）
    video      # 添加video模块（解决KalmanFilter错误）
    )
#添加opencv头文件路径（让编译器找到<opencv2/opencv.hpp>等）
include_directories(${OpenCV_INCLUDE_DIRS})



#链接opencv库（让连接器找到opencv的实现）
# link_directories(${OpenCV_LIBRARY_DIRS})


#==========依赖MVS相机SDK==========#
# MVS相机库的头文件路径
include_directories(/opt/MVS/include) 
# MVS相机库的头文件链接库路径
link_directories(/opt/MVS/lib/aarch64)

#==========依赖tensorRT==========#
find_path(TENSORRT_INCLUDE_DIR NvInfer.h
    HINTS  /usr/include/aarch64-linux-gnu/
    REQUIRED
)

find_library(TENSORRT_NVINFER nvinfer
    HINTS /usr/lib/aarch64-linux-gnu/
    REQUIRED
)
find_library(TENSORRT_NVINFER_PLUGIN nvinfer_plugin
    HINTS /usr/lib/aarch64-linux-gnu/
    REQUIRED
)
find_library(TENSORRT_NVONNX_PARSER nvonnxparser
    HINTS /usr/lib/aarch64-linux-gnu/
    REQUIRED
)
# 汇总tensorRT的头文件路径和链接库路径
set(TENSORRT_LIBS
    ${TENSORRT_NVINFER}
    ${TENSORRT_NVINFER_PLUGIN}
    ${TENSORRT_NVONNX_PARSER} # 如果需要ONNX支持的话
)
include_directories(${TENSORRT_INCLUDE_DIR})

#=========项目自身文件==========#
#添加项目私有头文件路径
include_directories(${PROJECT_SOURCE_DIR}/test/include)
include_directories(${PROJECT_SOURCE_DIR}/test/yolov8/include)

#自动收集test/src目录下的所有.cpp源文件到变量'SRC'
aux_source_directory(${PROJECT_SOURCE_DIR}/test/src SRC)
# set(SRC
#     ${PROJECT_SOURCE_DIR}/test/src/main.cpp
#     ${PROJECT_SOURCE_DIR}/test/src/yolov8_tensorrt.cpp
# )
aux_source_directory(${PROJECT_SOURCE_DIR}/test/yolov8/src SRC)

#生成可执行文件‘show’，依赖‘SRC’中的所有源文件
add_executable(show ${SRC})
# 链接库
# target_link_libraries(show 
#     ${OpenCV_LIBS}
# )
# 查找CUDA
find_package(CUDA REQUIRED)

include_directories(${CUDA_INCLUDE_DIRS}) # 添加cuda头文件库

link_directories(${CUDA_LIBRARY_DIRS}) # 添加cuda链接库

# 链接库
target_link_libraries(show 
    ${OpenCV_LIBS}
    ${CUDA_LIBRARIES}
    libMvCameraControl.so
    -lpthread
    -luuid
    # -lx11 # 若涉及图像显示，可能需要
    # cudnn  按道理来说这个是需要链接的，但是加了这个就会报错，不加好像也能用(test/src/cuda_cudnn.cpp)
    ${TENSORRT_LIBS}
    cudart
    cublas
    curand
)

